<?php

namespace App\Http\Controllers\Mini\Shop;

use App\Http\Controllers\Controller;
use App\Services\Keywords;

/**
 * Class KeywordsController
 * @package App\Http\Controllers\Mini\Shop
 * 2021/3/18 - 11:06
 * Administrator
 * 搜索热词控制器
 */
class KeywordsController extends Controller
{
    public $KeywordsService;

    public function __construct()
    {
        $this->KeywordsService = new Keywords();
    }

    /**
     * 2021/3/18--11:07
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:getList
     * @effect:获取关键词列表
     */
    public function getList()
    {
        try {
            return $this->KeywordsService->getKeywordsList();
        } catch (\Exception $e) {
            return $this->format_error($e->getMessage() . $e->getMessage());
        }
    }


    /**
     * 2021/3/18--11:28
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:addKeyword
     * @effect:添加关键词
     */
    public function addKeyword()
    {
        try {
            return $this->KeywordsService->addKeywords(request()->keyword);
        } catch (\Exception $e) {
            return $this->format_error($e->getMessage() . $e->getMessage());
        }
    }

    /**
     * 2021/3/18--14:03
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:clearHistory
     * @effect:清空搜索记录
     */
    public function clearHistory()
    {
        try {
            return $this->KeywordsService->clearHistory();
        } catch (\Exception $e) {
            return $this->format_error($e->getMessage());
        }
    }

    /**
     *析构方法
     */
    public function __destruct()
    {
        $this->KeywordsService;
    }
}
